package com.sinoglobal.sinostore.adapter;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sinoglobal.sinostore.R;
import com.sinoglobal.sinostore.bean.CommentVo;

/**
 * @Title: ShopWareCommentAdapter.java
 * @Package com.chiliring.sinoglobal.adapter
 * @Description: TODO(评论信息的Adapter)
 * @author czz
 * @date 2014-9-11 下午4:42:23
 */
public class ShopWareCommentAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<CommentVo> commentVolist;
	public ShopWareCommentAdapter(Context context,ArrayList<CommentVo> commentVolist) {
		this.context = context;
		this.commentVolist = commentVolist;
	}
	
	public ArrayList<CommentVo> getCommentVolist() {
		return commentVolist;
	}

	
	public void AddData(ArrayList<CommentVo> list) {
		if (list != null) {
			this.commentVolist.addAll(list);
		}
		notifyDataSetChanged();
	}
	
	public void clearData(){
		if(null != commentVolist){
			commentVolist.clear();
		}
		notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		if(null == commentVolist){
			return 0;
		}
		return commentVolist.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return commentVolist.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		CommentVo commentVo = commentVolist.get(position);
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.shop_warecomment_item, null);
		}
		TextView commentName = ViewHolder.getViewById(convertView, R.id.comment_name);
		TextView commentTime = ViewHolder.getViewById(convertView, R.id.comment_time);
		TextView commentMessage = ViewHolder.getViewById(convertView, R.id.comment_message);
		
		commentName.setText(commentVo.getNike_name());
		commentTime.setText(commentVo.getCreate_time());
		try {
			commentMessage.setText(URLDecoder.decode(commentVo.getMessage(), "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return convertView;
	}
}
